/**
  * @name 节流函数
  * @description: 
  * @param 
  * @return 
  */
import Vue from "vue"

Vue.directive("throttle",{
	bind(el,binding){
		console.log(binding)
		let fn = binding.value[0]
		let time = binding.value[1]

		let type = binding.arg
		
		function myThrottle(fn,time){
			let endTime = 0

			return function(){
				let nowTime = +new Date()

				if(nowTime-endTime>time){
					endTime = nowTime
					fn.apply(this,arguments)
				}
			}
		}
		let handler = myThrottle(fn,time)
		el.addEventListener(type,handler)
	}
})